/**
 * TechnicsServiceImpl.java
 * @author
 * 作者 屈甲康 
 */
package org.jackysoft.service.impl;

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.jackysoft.entity.Department;
import org.jackysoft.entity.Product;
import org.jackysoft.entity.Technics;
import org.jackysoft.service.AbstractStringIdServiceImpl;
import org.jackysoft.service.TechnicsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class TechnicsServiceImpl extends AbstractStringIdServiceImpl<Technics>
implements TechnicsService {
    /**
	 * 
	 */
	private static final long serialVersionUID = -5623130061979030977L;
	final static Log logger = LogFactory.getLog(TechnicsServiceImpl.class);

	public TechnicsServiceImpl(){
	    this.type = Technics.class;
	}

	
	@Override
	@SuppressWarnings("unchecked")
	public Collection<Technics> getsByProduct(Product p) {
		String hql=String.format("from %s t where t.product=:pdt",table());
		Query q = query(hql).setParameter("pdt", p);
		return q.list();
	}

	@Override
	public Technics get(Department department, Product p,String name) {
		String hql=String.format("from %s where product=:pdt and department=:dept and name=:name",table());
		Query q = query(hql).setParameter("pdt", p).setParameter("dept", department).setParameter("name", name);
		boolean hasnext = q.iterate().hasNext();
		return (Technics) (hasnext?q.iterate().next():null);
	}


	@Override
	public Technics get(Department department, Product p) {
		String hql=String.format("from %s where product=:pdt and department=:dept ",table());
		Query q = query(hql).setParameter("pdt", p).setParameter("dept", department);
		boolean hasnext = q.iterate().hasNext();
		return (Technics) (hasnext?q.iterate().next():null);
	}	
		
}